//    uniCenta oPOS - touch friendly EPoS
//    Copyright (c) 2009 uniCenta
//    http://www.unicenta.net
//
//    This file is part of uniCenta oPOS
//
//    uniCenta oPOS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    uniCenta oPOS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with uniCenta oPOS.  If not, see <http://www.gnu.org/licenses/>.
//		added by g.irura @ 27/03/2010. 
// 		CALCULATES PROFIT FOR EACH ITEM THAT IS SOLD AS WELL AS QUANTITY OF ITEMS OCCURRING IN THE PARTICULAR SALE
//		IF A PRICE ADJUSTMENT OCCURS, IT IS REFLECTED IN THE TRAIL OF RECEIPTS ON DATES. THE REPORT ALSO SHOWS THE TOTAL PROFITS MADE ON PRODUCTS/SERVICES SOLD

report = new com.openbravo.pos.reports.PanelReportBean();

report.setTitleKey("Menu.SalesProfit");
report.setReport("/com/openbravo/reports/productsalesprofit");
report.setResourceBundle("com/openbravo/reports/productsalesprofit_messages");

report.setSentence("SELECT PRODUCTS.CODE, "+
                        "TICKETS.TICKETID, "+
                        "RECEIPTS.DATENEW AS DATE, "+
                        "PRODUCTS.NAME, "+
                        "PRODUCTS.PRICEBUY, "+
                        "PRODUCTS.PRICESELL, "+
                        "SUM(TICKETLINES.UNITS) AS UNITSSOLD, "+
                        "SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) AS TOTAL, "+
                        "SUM(TICKETLINES.UNITS*(PRODUCTS.PRICESELL-PRODUCTS.PRICEBUY)) AS PROFITLOSS "+
                        "FROM RECEIPTS, TICKETS, TICKETLINES, PRODUCTS "+
                        "WHERE RECEIPTS.ID = TICKETS.ID AND TICKETS.ID = TICKETLINES.TICKET AND TICKETLINES.PRODUCT = PRODUCTS.ID AND ?(QBF_FILTER)"+
                        "GROUP BY PRODUCTS.CODE, PRODUCTS.NAME , TICKETS.TICKETID, RECEIPTS.DATENEW, PRODUCTS.PRICEBUY, PRODUCTS.PRICESELL "+
                        "ORDER BY RECEIPTS.DATENEW");

report.addParameter("RECEIPTS.DATENEW");
report.addParameter("RECEIPTS.DATENEW");
paramdates = new com.openbravo.pos.reports.JParamsDatesInterval();
paramdates.setEndDate(com.openbravo.beans.DateUtils.getToday());
report.addQBFFilter(paramdates);

report.addField("CODE", com.openbravo.data.loader.Datas.STRING);
report.addField("TICKETID", com.openbravo.data.loader.Datas.INT);
report.addField("DATE", com.openbravo.data.loader.Datas.TIMESTAMP);
report.addField("NAME", com.openbravo.data.loader.Datas.STRING);
report.addField("PRICEBUY", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("PRICESELL", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("UNITSSOLD", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("TOTAL", com.openbravo.data.loader.Datas.DOUBLE);
report.addField("PROFITLOSS", com.openbravo.data.loader.Datas.DOUBLE);


report;